import { PermissionAll } from '@/services/permission';
import { useMemo, useState } from 'react';

const usePermission = () => {
  const [list, setList] = useState([]);
  const fetchData = async () => {
    const res = await PermissionAll();
    setList(res.data);
  };
  const obj = useMemo(() => {
    const obj: any = {};
    list.forEach((item: any) => {
      obj[item.id] = item;
    });
    return obj;
  }, [list]);

  return {
    list,
    obj,
    refetch: fetchData,
  };
};

export default usePermission;
